#include <cmdSetReadSN.h>
#include <deviceOperateSN.h>

void masterCmdCvrtFuncName(SetReadSN)(struct masterCmdStructName(SetReadSN) *masterData)
{
    masterData = NULL;
}
void devCmdCvrtFuncName(SetReadSN)(struct devCmdStructName(SetReadSN) *devData)
{
    devData = NULL;
}
int devCmdDealFuncName(SetReadSN)(struct ptcCmdOptStruct *cmdOpt)
{
    struct masterCmdStructName(SetReadSN) *masterData = ptcCmdGetUsrPtr(cmdOpt);
    struct devCmdStructName(SetReadSN) *devData = ptcCmdGetUsrPtr(cmdOpt);
    int tmpResult = cmdExeRslt_OK;
    if(ptcCmdGetUserSize(cmdOpt) < sizeof(struct masterCmdStructName(SetReadSN)))
    {
        logerror("%d", ptcCmdGetUserSize(cmdOpt));
        tmpResult = cmdExeRslt_MasterSizeErr;
        goto cmdDealErrorResp;
    }
    // do user logic
    logHexData("SetReadSN:", masterData->setSn, sizeof(masterData->setSn));
    deviceSnSaveToHardware(masterData->setSn);
    // pack response user data
    if(ptcCmdSetUsrSize(cmdOpt, sizeof(struct devCmdStructName(SetReadSN))) < 0)
    {
        logerror("%d", sizeof(struct devCmdStructName(SetReadSN)));
        tmpResult = cmdExeRslt_DevSizeErr;
        goto cmdDealErrorResp;
    }
    memcpypro(devData->version, sizeof(devData->version), DEVICE_VERSION_STR_DATA, sizeof(DEVICE_VERSION_STR_DATA));
    memcpypro(devData->serialnumber, sizeof(devData->serialnumber), deviceSnString, sizeof(deviceSnString));
cmdDealErrorResp:
    // pack response cmd head
    if(tmpResult != cmdExeRslt_OK)
    {
        ptcCmdSetUsrSize(cmdOpt, 0);
    }
    ptcCmdSetCmdResp(cmdOpt, tmpResult);
    ptcPackSetCrypte(&cmdOpt->parser, protocolParseCrypte_None);// set crypte type if you want
    // pack pack head by 485 cmd function. there not config
    return 0;
}
